package view;

import model.Address;
import control.AddressHandler;
import control.CargoHandler;
import control.CustomerHandler;
import control.DistanceHandler;
import control.DriverHandler;
import control.TaskHandler;
import control.VehicleHandler;
import model.Cargo;
import model.Customer;
import model.Driver;
import control.NumberRestrictionDocument;
import model.Task;
import model.Vehicle;
import java.util.ArrayList;
import java.util.Date;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

/**
 *
 * @author Mikkel, Maja Og Jeppe
 */
public class OpretOpgave extends javax.swing.JPanel {

    private Main main;
    private String description;
    private String cargoType;
    private int cargoWeight;
    private int cargoNumber;
    private boolean dangCargo;
    private Cargo cargo;
    private Driver driver;
    private Customer customer;
    private Address pickUpAddress;
    private Address deliveryAddress;
    private Task theTask;
    private AddressHandler addressHandler;
    private CustomerHandler customerHandler;
    private DriverHandler driverHandler;
    private DistanceHandler distanceHandler;
    private CargoHandler cargoHandler;
    private VehicleHandler vehicleHandler;
    private TaskHandler taskHandler;
    private Date date;
    private boolean clearRunning = false;

    /**
     * Creates new form OpretOpgave
     */
    public OpretOpgave(Main main) {
        initComponents();
        this.main = main;
        dangCargo = false;
        driverHandler = main.getDriverHandler();
        addressHandler = main.getAddressHandler();
        customerHandler = main.getCustomerHandler();
        vehicleHandler = main.getVehicleHandler();
        distanceHandler = main.getDistanceHandler();
        cargoHandler = main.getCargoHandler();
        taskHandler = main.getTaskHandler();
        theTask = new Task();
        date = new Date();
//        System.out.println("Dato valgt: " + jCalendar1.getDate().toLocaleString());
        jCalendar1.setSelectableDateRange(date, null);
        cargoType = "pallet";

    }

    public void errorMsg(String fejl) {
//        JOptionPane.showMessageDialog(this, fejl);
//        JOptionPane.showInternalMessageDialog(main, fejl, "Fejlmeddelelse", 3);
        JOptionPane.showMessageDialog(this, fejl, "Fejlmeddelelse", 3);
    }

    private void checkPickUpAddress() {
        boolean afhentAdresse = true;
        boolean afhentZipCode = false;
        boolean afhentByBool = true;
        boolean afhentDisBool = true;
        boolean afhentLandBool = true;

        if (afhentAdr.getText().equals("Afhentningsadresse") || afhentAdr.getText().equals("")) {
            afhentAdresse = false;
        }
        if (afhentzip.getText().matches("\\d+")) {
            afhentZipCode = true;
        }
        if (afhentByCombo.getSelectedItem().equals("By") || afhentByCombo.getSelectedItem().equals("")) {
            afhentByBool = false;
        }
        if (afhentdis.getText().equals("Distrikt")) {
            afhentDisBool = false;
        }
        if (afhentLand.getText().equals("Land") || afhentLand.getText().equals("")) {
            afhentLandBool = false;
        }
        if (afhentAdresse && afhentByBool && afhentDisBool && afhentLandBool && afhentZipCode && !clearRunning) {
            Address aAddress = new Address(afhentCompanytxt.getText(), afhentAdr.getText(), afhentzip.getText(), (String) afhentByCombo.getSelectedItem(), afhentdis.getText(), afhentLand.getText());
            System.out.println(aAddress.toString());
            if (addressHandler.tjekAddressByAllParameters(aAddress.getCompany(), aAddress.getAddress(), aAddress.getZipcode(), aAddress.getCity(), aAddress.getDistrict() + "", aAddress.getCountry())) {
                pickUpAddress = addressHandler.getAddressByAllParameters(afhentCompanytxt.getText(), afhentAdr.getText(), afhentzip.getText(), (String) afhentByCombo.getSelectedItem(), afhentdis.getText() + "", afhentLand.getText());
                theTask.setPickUpAddress(pickUpAddress);
            } else {
                pickUpAddress = aAddress;
                addressHandler.insertToDB(aAddress);
                pickUpAddress = addressHandler.getAddressByAllParameters(afhentCompanytxt.getText(), afhentAdr.getText(), afhentzip.getText(), (String) afhentByCombo.getSelectedItem(), afhentdis.getText() + "", afhentLand.getText());
            }

        } else {
            pickUpAddress = null;
        }
        setCargo();
        setVehicleCombo();
        setDriverCombo();
        setFields();
    }

    private void checkDeliveryAddress() {
        boolean leveringsAdresse = true;
        boolean leveringsZipCode = false;
        boolean leveringsByBool = true;
        boolean leveringsDisBool = true;
        boolean leveringsLandBool = true;
        if (levadrtxt.getText().equals("Leveringsadresse") || levadrtxt.getText().equals("")) {
            leveringsAdresse = false;
        }
        if (levzip.getText().matches("\\d+")) {
            leveringsZipCode = true;
        }
        if (levByCombo.getSelectedItem().equals("By") || levByCombo.getSelectedItem().equals("")) {
            leveringsByBool = false;
        }
        if (levdis.getText().equals("Distrikt")) {
            leveringsDisBool = false;
        }
        if (levLand.getText().equals("Land") || levLand.getText().equals("")) {
            leveringsLandBool = false;
        }
        if (leveringsAdresse && leveringsByBool && leveringsDisBool && leveringsLandBool && leveringsZipCode && !clearRunning) {
            Address aAddress = new Address(levcom.getText(), levadrtxt.getText(), levzip.getText(), (String) levByCombo.getSelectedItem(), levdis.getText() + "", levLand.getText());
            if (addressHandler.tjekAddressByAllParameters(aAddress.getCompany(), aAddress.getAddress(), aAddress.getZipcode(), aAddress.getCity(), aAddress.getDistrict(), aAddress.getCountry())) {
                deliveryAddress = addressHandler.getAddressByAllParameters(aAddress.getCompany(), aAddress.getAddress(), aAddress.getZipcode(), aAddress.getCity(), aAddress.getDistrict() + "", aAddress.getCountry());
            } else {
                deliveryAddress = aAddress;
                addressHandler.insertToDB(aAddress);
            }
        } else {
            deliveryAddress = null;
        }
        setVehicleCombo();
        setDriverCombo();
        setFields();
    }

    private void setVehicleCombo() {
        vehicleCombo.removeAllItems();
        ArrayList<Vehicle> vehicleList = new ArrayList<>();
        theTask.setDd(jCalendar1.getDate().getDate());
        theTask.setMm(jCalendar1.getDate().getMonth() + 1);
        theTask.setYYYY(jCalendar1.getDate().getYear() + 1900);
        if (cargoType != null && weighttxt.getText().matches("\\d+") && Antalfragt.getText().matches("\\d+")) {
//            System.out.println("Vi er parate til at tilføje Vogne (setVehicleCombo)");
            vehicleList = vehicleHandler.getVehicleListByAll(Integer.parseInt(Antalfragt.getText()), Integer.parseInt(weighttxt.getText()), cargoType, theTask.getDD(), theTask.getMM(), theTask.getYYYY());
        } else {
//            System.out.println("Der er ikke indtastet korrekt data i vægt eller antal.");
        }
//        System.out.println("Vi har fundet " + vehicleList.size() + " Køretøjer til dem");
        for (int i = 0; i < vehicleList.size(); i++) {
            vehicleCombo.addItem(vehicleList.get(i));
        }
    }

    private void setDriverCombo() {
        driverCombo.removeAllItems();
        boolean EU = false;
        theTask.setDd(jCalendar1.getDate().getDate());
        theTask.setMm(jCalendar1.getDate().getMonth() + 1);
        theTask.setYYYY(jCalendar1.getDate().getYear() + 1900);
        if (pickUpAddress != null && deliveryAddress != null) {
            if (pickUpAddress.getCountry().equals("Tyskland") || pickUpAddress.getCountry().equals("Holland") || pickUpAddress.getCountry().equals("Belgien")
                    || deliveryAddress.getCountry().equalsIgnoreCase("Tyskland") || deliveryAddress.getCountry().equals("Holland") || deliveryAddress.getCountry().equals("Belgien")) {
                EU = true;
            }

            ArrayList<Driver> driverList = driverHandler.getDriverListByCertificateNY(farligtGodsCheck.isSelected(), SpecielFragtRadio.isSelected(), EU, theTask.getDD(), theTask.getMM(), theTask.getYYYY());
            for (int i = 0; i < driverList.size(); i++) {
                driverCombo.addItem(driverList.get(i));
            }
            if (EU && jCalendar1.getDate().getDay() == 0) {
                driverCombo.removeAllItems();
                errorMsg("HUSK, at Næstved Vejtransport IKKE kører til Tyskland om søndagen.\nDu har valgt d. " + theTask.getDD() + "/" + theTask.getMM() + "-" + theTask.getYYYY());
            }
        }
    }

    private void setCustomer() {
        if (tlfnrTxt.getText() != null && kundenavntxt.getText() != null && kundeAdrTxt.getText() != null && kundePostnrTxt.getText() != null && kundeByTxt.getText() != null) {
            if (customer != null) {
                theTask.setCustomer(customer);
            }
        }
    }

    private void setCargo() {
        if (weighttxt.getText().matches("\\d+")) {
            cargoWeight = Integer.parseInt(weighttxt.getText());
            theTask.setCargoWeight(cargoWeight);
        } else if (!weighttxt.getText().equals("") && weighttxt.getText() != null) {
            errorMsg("Du er nødt til at indtaste en vægt med tal");
        }
        if (Antalfragt.getText().matches("\\d+")) {
            cargoNumber = Integer.parseInt(Antalfragt.getText());
            theTask.setCargoNumber(cargoNumber);
        }
        if (cargoType != null) {
            theTask.setCargoType(cargoType);
        }
        if (cargoType != null) {
            if (weighttxt.getText().matches("\\d+") && Antalfragt.getText().matches("\\d+")) {
                if (cargoHandler.getCargo(cargoType, Integer.parseInt(weighttxt.getText()), Integer.parseInt(Antalfragt.getText())) != null) {
                    theTask.setCargo(cargoHandler.getCargo(cargoType, Integer.parseInt(weighttxt.getText()), Integer.parseInt(Antalfragt.getText())));
                } else {
                    errorMsg("Vi kan desværre ikke fragte " + theTask.getCargoNumberString() + "\nmed en vægt på " + theTask.getCargoWeight() + " kg.\nPrøv med specialfragt som går op til 35K Kilo");
                }
            }
        }

    }

    private void setFields() {
        theTask.setDd(jCalendar1.getDate().getDate());
        theTask.setMm(jCalendar1.getDate().getMonth() + 1);
        theTask.setYYYY(jCalendar1.getDate().getYear() + 1900);
        theTask.setDangCargo(farligtGodsCheck.isSelected());

        if (pickUpAddress != null && deliveryAddress != null && !clearRunning) {
//            System.out.println("HVORFOR MIIIIG?! :/");
            if (distanceHandler.checkDistanceByCities(pickUpAddress.getCity(), deliveryAddress.getCity())) {
                theTask.setPickUpAddress(pickUpAddress);
                theTask.setDeliveryAddress(deliveryAddress);
                theTask.setDistance(distanceHandler.getDistanceByCities(theTask.getPickUpAddress().getCity(), theTask.getDeliveryAddress().getCity()));
//                System.out.println("Sætter distanceobjekt til: " + distanceHandler.getDistanceByCities(pickUpAddress.getCity(), deliveryAddress.getCity()).toString());
                RuteLabel.setText(theTask.getDistance().getStartDestination() + " - " + theTask.getDistance().getEndDestination());
                antalKmLabel.setText(theTask.getDistance().getDistance() + "");
            } else {
                errorMsg("Vær opmærksom på, at Næstved Vejtransport IKKE \nfragter mellem " + pickUpAddress.getCity() + " og " + deliveryAddress.getCity() + ".");
            }
        }

        if (theTask != null) {
            if (theTask.getDistance() != null && theTask.getCargo() != null) {
                prisLabel.setText(taskHandler.getPrice(theTask));
//                System.out.println("VI SÆTTER PRIS :D 8D");
            } else {
                prisLabel.setText("");
            }
        }

        if (theTask.getCargo() != null) {
//            System.out.println("1");
            if (theTask.getCargoType() != null) {
//                System.out.println("2");
                if (theTask.getCustomer() != null) {
//                    System.out.println("3");
                    if (theTask.getPickUpAddress() != null) {
//                        System.out.println("4");
                        if (theTask.getDeliveryAddress() != null) {
//                            System.out.println("5");
                            if (theTask.getDistance() != null) {
//                                System.out.println("6");
                                if (theTask.getDriver() != null) {
//                                    System.out.println("7");
                                    if (theTask.getVehicle() != null) {
//                                        System.out.println("8");
                                        opretOpgaveKnap.setEnabled(true);
                                    } else {
                                        opretOpgaveKnap.setEnabled(false);
                                    }
                                } else {
                                    opretOpgaveKnap.setEnabled(false);
                                }
                            } else {
                                opretOpgaveKnap.setEnabled(false);
                            }
                        } else {
                            opretOpgaveKnap.setEnabled(false);
                        }
                    } else {
                        opretOpgaveKnap.setEnabled(false);
                    }
                } else {
                    opretOpgaveKnap.setEnabled(false);
                }
            } else {
                opretOpgaveKnap.setEnabled(false);
            }
        } else {
            opretOpgaveKnap.setEnabled(false);
        }
    }

    private void clearFields() {

        clearRunning = true;

        afhentByCombo.removeAllItems();
        levByCombo.removeAllItems();

        for (int i = 0; i < distanceHandler.getAllCities().size(); i++) {
            afhentByCombo.addItem(distanceHandler.getAllCities().get(i));
            levByCombo.addItem(distanceHandler.getAllCities().get(i));
        }

        tlfnrTxt.setText("Find på tlfnr");
        kundenavntxt.setText("Navn");
        kundeAdrTxt.setText("Adresse");
        kundePostnrTxt.setText("Postnr");
        kundeByTxt.setText("By");
        afhentCompanytxt.setText("Firmanavn (Kan efterlades blank)");
        afhentAdr.setText("Adresse");
        afhentzip.setText("Postnr");
        afhentByCombo.setSelectedIndex(0);
        afhentdis.setText("Distrikt");
        afhentLand.setText("Land");
        levcom.setText("Firmanavn (Kan efterlades blank)");
        levadrtxt.setText("Adresse");
        levzip.setText("Postnr");
        levByCombo.setSelectedIndex(0);
        levdis.setText("Distrikt");
        levLand.setText("Land");
        antalKmLabel.setText("");
        Antalfragt.setText("Antal");
        fragtEnhedLabel.setText("Paller");
        RuteLabel.setText("");
        weighttxt.setText("kg");
        farligtGodsCheck.setSelected(false);
        PallefragtRadio.setSelected(true);
        prisLabel.setText("");
        descriptionArea.setText("");

        cargoType = "pallet";
        pickUpAddress = null;
        deliveryAddress = null;
        customer = null;
        cargo = null;
        driver = null;
        theTask = new Task();

        jCalendar1.setDate(new Date());
        clearRunning = false;


    }

    public void setTlfnrTxt(String tlfnr) {
        tlfnrTxt.setText(tlfnr);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        cargoButtonGroup = new javax.swing.ButtonGroup();
        TitelLabel = new javax.swing.JLabel();
        tilbageKnap = new javax.swing.JButton();
        TOPPanel = new javax.swing.JPanel();
        opretOpgaveKnap = new javax.swing.JButton();
        jCalendar1 = new com.toedter.calendar.JCalendar();
        jLabel4 = new javax.swing.JLabel();
        StatusLabel = new javax.swing.JLabel();
        AfhentningsAdressePanel = new javax.swing.JPanel();
        afhentningsadresseLabel = new javax.swing.JLabel();
        afhentAdr = new javax.swing.JTextField();
        afhentzip = new javax.swing.JTextField();
        afhentdis = new javax.swing.JTextField();
        afhentLand = new javax.swing.JTextField();
        afhentCompanytxt = new javax.swing.JTextField();
        sameAsCustomer_Knap = new javax.swing.JButton();
        afhentByCombo = new javax.swing.JComboBox();
        jPanel3 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        levadrtxt = new javax.swing.JTextField();
        levLand = new javax.swing.JTextField();
        levcom = new javax.swing.JTextField();
        levzip = new javax.swing.JTextField();
        levdis = new javax.swing.JTextField();
        sameAsCustomerDelKnap = new javax.swing.JButton();
        levByCombo = new javax.swing.JComboBox();
        jPanel4 = new javax.swing.JPanel();
        tlfnrTxt = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        kundenavntxt = new javax.swing.JTextField();
        kundeAdrTxt = new javax.swing.JTextField();
        kundePostnrTxt = new javax.swing.JTextField();
        kundeByTxt = new javax.swing.JTextField();
        OpretNyKunde = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        PallefragtRadio = new javax.swing.JRadioButton();
        Antalfragt = new javax.swing.JTextField();
        StykGodsRadio = new javax.swing.JRadioButton();
        SpecielFragtRadio = new javax.swing.JRadioButton();
        jLabel8 = new javax.swing.JLabel();
        fragtEnhedLabel = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jSeparator2 = new javax.swing.JSeparator();
        jSeparator4 = new javax.swing.JSeparator();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        RuteLabel = new javax.swing.JLabel();
        KmPanel = new javax.swing.JPanel();
        Label8 = new javax.swing.JLabel();
        farligtGodsCheck = new javax.swing.JCheckBox();
        jSeparator5 = new javax.swing.JSeparator();
        jSeparator3 = new javax.swing.JSeparator();
        jSeparator7 = new javax.swing.JSeparator();
        jSeparator6 = new javax.swing.JSeparator();
        VægtPanel = new javax.swing.JPanel();
        Label9 = new javax.swing.JLabel();
        weighttxt = new javax.swing.JTextField();
        pricePanel = new javax.swing.JPanel();
        Label7 = new javax.swing.JLabel();
        prisLabel = new javax.swing.JLabel();
        descriptionPanel = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        descriptionArea = new javax.swing.JTextArea();
        driverVehiclePanel = new javax.swing.JPanel();
        driverCombo = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        vehicleCombo = new javax.swing.JComboBox();
        Label6 = new javax.swing.JLabel();
        antalKmLabel = new javax.swing.JLabel();
        clearKnap = new javax.swing.JButton();
        background = new javax.swing.JLabel();

        setMinimumSize(new java.awt.Dimension(1899, 1033));
        setPreferredSize(new java.awt.Dimension(1899, 1033));
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                formComponentShown(evt);
            }
        });
        setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        TitelLabel.setFont(new java.awt.Font("Garamond", 1, 48)); // NOI18N
        TitelLabel.setForeground(new java.awt.Color(255, 255, 255));
        TitelLabel.setText("Fragtseddel");
        add(TitelLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(290, 0, 260, 60));

        tilbageKnap.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pictures/backbutton.png"))); // NOI18N
        tilbageKnap.setText("Tilbage");
        tilbageKnap.setContentAreaFilled(false);
        tilbageKnap.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tilbageKnapActionPerformed(evt);
            }
        });
        add(tilbageKnap, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, 90, 30));

        TOPPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255), 2));
        TOPPanel.setMinimumSize(new java.awt.Dimension(1899, 1033));
        TOPPanel.setOpaque(false);
        TOPPanel.setPreferredSize(new java.awt.Dimension(1899, 1033));
        TOPPanel.setLayout(null);

        opretOpgaveKnap.setText("Opret opgave");
        opretOpgaveKnap.setEnabled(false);
        opretOpgaveKnap.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                opretOpgaveKnapActionPerformed(evt);
            }
        });
        TOPPanel.add(opretOpgaveKnap);
        opretOpgaveKnap.setBounds(639, 600, 140, 25);

        jCalendar1.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jCalendar1PropertyChange(evt);
            }
        });
        TOPPanel.add(jCalendar1);
        jCalendar1.setBounds(410, 10, 390, 140);

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        jLabel4.setForeground(new java.awt.Color(255, 255, 255));
        jLabel4.setText("Dato:");
        TOPPanel.add(jLabel4);
        jLabel4.setBounds(420, 10, 214, 16);
        TOPPanel.add(StatusLabel);
        StatusLabel.setBounds(430, 610, 350, 30);

        AfhentningsAdressePanel.setOpaque(false);

        afhentningsadresseLabel.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        afhentningsadresseLabel.setForeground(new java.awt.Color(255, 255, 255));
        afhentningsadresseLabel.setText("Afhentningsadresse:");

        afhentAdr.setText("Afhentningsadresse");
        afhentAdr.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                afhentAdrFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                afhentAdrFocusLost(evt);
            }
        });

        afhentzip.setEditable(false);
        afhentzip.setBackground(new java.awt.Color(201, 201, 201));
        afhentzip.setText("Postnr");
        afhentzip.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                afhentzipFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                afhentzipFocusLost(evt);
            }
        });

        afhentdis.setText("Distrikt");
        afhentdis.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                afhentdisFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                afhentdisFocusLost(evt);
            }
        });

        afhentLand.setEditable(false);
        afhentLand.setBackground(new java.awt.Color(201, 201, 201));
        afhentLand.setText("Land");
        afhentLand.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                afhentLandFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                afhentLandFocusLost(evt);
            }
        });

        afhentCompanytxt.setText("Firmanavn (Kan efterlades blankt)");
        afhentCompanytxt.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                afhentCompanytxtFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                afhentCompanytxtFocusLost(evt);
            }
        });

        sameAsCustomer_Knap.setBackground(new java.awt.Color(255, 255, 255));
        sameAsCustomer_Knap.setFont(new java.awt.Font("Tahoma", 3, 11)); // NOI18N
        sameAsCustomer_Knap.setForeground(new java.awt.Color(255, 255, 255));
        sameAsCustomer_Knap.setText("Samme som kundeadresse");
        sameAsCustomer_Knap.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        sameAsCustomer_Knap.setContentAreaFilled(false);
        sameAsCustomer_Knap.setInheritsPopupMenu(true);
        sameAsCustomer_Knap.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sameAsCustomer_KnapActionPerformed(evt);
            }
        });

        afhentByCombo.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                afhentByComboItemStateChanged(evt);
            }
        });

        javax.swing.GroupLayout AfhentningsAdressePanelLayout = new javax.swing.GroupLayout(AfhentningsAdressePanel);
        AfhentningsAdressePanel.setLayout(AfhentningsAdressePanelLayout);
        AfhentningsAdressePanelLayout.setHorizontalGroup(
            AfhentningsAdressePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(afhentAdr)
            .addComponent(afhentCompanytxt, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
            .addGroup(AfhentningsAdressePanelLayout.createSequentialGroup()
                .addComponent(afhentzip, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(afhentByCombo, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(afhentdis, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(AfhentningsAdressePanelLayout.createSequentialGroup()
                .addComponent(afhentningsadresseLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(sameAsCustomer_Knap, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
            .addComponent(afhentLand)
        );
        AfhentningsAdressePanelLayout.setVerticalGroup(
            AfhentningsAdressePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(AfhentningsAdressePanelLayout.createSequentialGroup()
                .addGroup(AfhentningsAdressePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(afhentningsadresseLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(sameAsCustomer_Knap, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(afhentCompanytxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(afhentAdr, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(AfhentningsAdressePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(afhentzip, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(afhentdis, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(afhentByCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(afhentLand, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 8, Short.MAX_VALUE))
        );

        TOPPanel.add(AfhentningsAdressePanel);
        AfhentningsAdressePanel.setBounds(10, 170, 380, 140);

        jPanel3.setOpaque(false);

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        jLabel6.setForeground(new java.awt.Color(255, 255, 255));
        jLabel6.setText("Leveringsadresse:");

        levadrtxt.setText("Leveringsadresse");
        levadrtxt.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                levadrtxtFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                levadrtxtFocusLost(evt);
            }
        });

        levLand.setEditable(false);
        levLand.setBackground(new java.awt.Color(201, 201, 201));
        levLand.setText("Land");
        levLand.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                levLandFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                levLandFocusLost(evt);
            }
        });

        levcom.setText("Firmanavn (Kan efterlades blankt)");
        levcom.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                levcomFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                levcomFocusLost(evt);
            }
        });

        levzip.setEditable(false);
        levzip.setBackground(new java.awt.Color(201, 201, 201));
        levzip.setText("Postnr");
        levzip.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                levzipFocusLost(evt);
            }
            public void focusGained(java.awt.event.FocusEvent evt) {
                levzipFocusGained(evt);
            }
        });

        levdis.setText("Distrikt ");
        levdis.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                levdisFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                levdisFocusLost(evt);
            }
        });

        sameAsCustomerDelKnap.setFont(new java.awt.Font("Tahoma", 3, 11)); // NOI18N
        sameAsCustomerDelKnap.setForeground(new java.awt.Color(255, 255, 255));
        sameAsCustomerDelKnap.setText("Samme som kundeadresse");
        sameAsCustomerDelKnap.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        sameAsCustomerDelKnap.setContentAreaFilled(false);
        sameAsCustomerDelKnap.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sameAsCustomerDelKnapActionPerformed(evt);
            }
        });

        levByCombo.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                levByComboItemStateChanged(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(sameAsCustomerDelKnap, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 100, Short.MAX_VALUE))
                    .addComponent(levLand)
                    .addComponent(levcom)
                    .addComponent(levadrtxt)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(levzip, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(levByCombo, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(levdis, javax.swing.GroupLayout.DEFAULT_SIZE, 144, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(sameAsCustomerDelKnap, javax.swing.GroupLayout.PREFERRED_SIZE, 16, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(levcom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(levadrtxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(levzip, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(levdis, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(levByCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(levLand, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        TOPPanel.add(jPanel3);
        jPanel3.setBounds(410, 170, 400, 140);

        jPanel4.setOpaque(false);

        tlfnrTxt.setText("Find på tlfnr");
        tlfnrTxt.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                tlfnrTxtFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                tlfnrTxtFocusLost(evt);
            }
        });
        tlfnrTxt.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                tlfnrTxtKeyReleased(evt);
            }
        });

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        jLabel7.setForeground(new java.awt.Color(255, 255, 255));
        jLabel7.setText("Kunde:");

        kundenavntxt.setEditable(false);
        kundenavntxt.setBackground(new java.awt.Color(201, 201, 201));
        kundenavntxt.setText("Navn");
        kundenavntxt.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                kundenavntxtFocusGained(evt);
            }
        });

        kundeAdrTxt.setEditable(false);
        kundeAdrTxt.setBackground(new java.awt.Color(201, 201, 201));
        kundeAdrTxt.setText("Adresse");
        kundeAdrTxt.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                kundeAdrTxtFocusGained(evt);
            }
        });

        kundePostnrTxt.setEditable(false);
        kundePostnrTxt.setBackground(new java.awt.Color(201, 201, 201));
        kundePostnrTxt.setText("Postnr");
        kundePostnrTxt.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                kundePostnrTxtFocusGained(evt);
            }
        });

        kundeByTxt.setEditable(false);
        kundeByTxt.setBackground(new java.awt.Color(201, 201, 201));
        kundeByTxt.setText("By");
        kundeByTxt.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                kundeByTxtFocusGained(evt);
            }
        });

        OpretNyKunde.setBackground(new java.awt.Color(255, 255, 255));
        OpretNyKunde.setFont(new java.awt.Font("Tahoma", 3, 11)); // NOI18N
        OpretNyKunde.setForeground(new java.awt.Color(255, 255, 255));
        OpretNyKunde.setText("Opret ny kunde her");
        OpretNyKunde.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        OpretNyKunde.setContentAreaFilled(false);
        OpretNyKunde.setInheritsPopupMenu(true);
        OpretNyKunde.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                OpretNyKundeActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
        jLabel2.setText("eller");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(86, 86, 86)
                .addComponent(kundeByTxt, javax.swing.GroupLayout.DEFAULT_SIZE, 294, Short.MAX_VALUE))
            .addComponent(kundenavntxt)
            .addComponent(kundeAdrTxt)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(kundePostnrTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addContainerGap(306, Short.MAX_VALUE))
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(tlfnrTxt)
                .addGap(18, 18, 18)
                .addComponent(jLabel2)
                .addGap(18, 18, 18)
                .addComponent(OpretNyKunde, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tlfnrTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(OpretNyKunde))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(kundenavntxt, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(kundeAdrTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(kundePostnrTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(kundeByTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        TOPPanel.add(jPanel4);
        jPanel4.setBounds(10, 10, 380, 150);

        jPanel5.setOpaque(false);
        jPanel5.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        cargoButtonGroup.add(PallefragtRadio);
        PallefragtRadio.setForeground(new java.awt.Color(255, 255, 255));
        PallefragtRadio.setSelected(true);
        PallefragtRadio.setText("Pallefragt");
        PallefragtRadio.setContentAreaFilled(false);
        PallefragtRadio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PallefragtRadioActionPerformed(evt);
            }
        });
        jPanel5.add(PallefragtRadio, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 20, -1, -1));

        Antalfragt.setText("Antal");
        Antalfragt.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                AntalfragtFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                AntalfragtFocusLost(evt);
            }
        });
        Antalfragt.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                AntalfragtKeyReleased(evt);
            }
        });
        Antalfragt.setDocument(new NumberRestrictionDocument(2));
        jPanel5.add(Antalfragt, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 50, 60, -1));

        cargoButtonGroup.add(StykGodsRadio);
        StykGodsRadio.setForeground(new java.awt.Color(255, 255, 255));
        StykGodsRadio.setText("Stykgods");
        StykGodsRadio.setContentAreaFilled(false);
        StykGodsRadio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                StykGodsRadioActionPerformed(evt);
            }
        });
        jPanel5.add(StykGodsRadio, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 50, -1, -1));

        cargoButtonGroup.add(SpecielFragtRadio);
        SpecielFragtRadio.setForeground(new java.awt.Color(255, 255, 255));
        SpecielFragtRadio.setText("Speciel fragt");
        SpecielFragtRadio.setContentAreaFilled(false);
        SpecielFragtRadio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SpecielFragtRadioActionPerformed(evt);
            }
        });
        jPanel5.add(SpecielFragtRadio, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 80, -1, -1));

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        jLabel8.setForeground(new java.awt.Color(255, 255, 255));
        jLabel8.setText("Fragttype:");
        jPanel5.add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, -1, -1));

        fragtEnhedLabel.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        fragtEnhedLabel.setForeground(new java.awt.Color(255, 255, 255));
        fragtEnhedLabel.setText("Paller");
        jPanel5.add(fragtEnhedLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 50, 110, 20));

        TOPPanel.add(jPanel5);
        jPanel5.setBounds(0, 350, 400, 120);

        jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);
        TOPPanel.add(jSeparator1);
        jSeparator1.setBounds(400, 0, 10, 650);
        TOPPanel.add(jSeparator2);
        jSeparator2.setBounds(0, 160, 810, 10);
        TOPPanel.add(jSeparator4);
        jSeparator4.setBounds(0, 310, 810, 10);

        jPanel1.setOpaque(false);
        jPanel1.setLayout(null);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("Rute:");
        jPanel1.add(jLabel1);
        jLabel1.setBounds(10, 10, 36, 16);

        RuteLabel.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
        RuteLabel.setForeground(new java.awt.Color(255, 255, 255));
        jPanel1.add(RuteLabel);
        RuteLabel.setBounds(52, 0, 270, 40);

        TOPPanel.add(jPanel1);
        jPanel1.setBounds(0, 310, 400, 40);

        KmPanel.setOpaque(false);
        KmPanel.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        Label8.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        Label8.setForeground(new java.awt.Color(255, 255, 255));
        Label8.setText("Km:");
        KmPanel.add(Label8, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, -1, -1));

        TOPPanel.add(KmPanel);
        KmPanel.setBounds(400, 310, 410, 40);

        farligtGodsCheck.setForeground(new java.awt.Color(255, 255, 255));
        farligtGodsCheck.setContentAreaFilled(false);
        farligtGodsCheck.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                farligtGodsCheckActionPerformed(evt);
            }
        });
        TOPPanel.add(farligtGodsCheck);
        farligtGodsCheck.setBounds(500, 400, 40, 25);
        TOPPanel.add(jSeparator5);
        jSeparator5.setBounds(400, 430, 410, 10);
        TOPPanel.add(jSeparator3);
        jSeparator3.setBounds(0, 470, 810, 20);
        TOPPanel.add(jSeparator7);
        jSeparator7.setBounds(400, 390, 410, 10);
        TOPPanel.add(jSeparator6);
        jSeparator6.setBounds(0, 350, 810, 20);

        VægtPanel.setOpaque(false);
        VægtPanel.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        Label9.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        Label9.setForeground(new java.awt.Color(255, 255, 255));
        Label9.setText("Vægt:");
        VægtPanel.add(Label9, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 10, -1, -1));

        weighttxt.setText("kg");
        weighttxt.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                weighttxtFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                weighttxtFocusLost(evt);
            }
        });
        weighttxt.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                weighttxtKeyReleased(evt);
            }
        });
        weighttxt.setDocument(new NumberRestrictionDocument(5));
        VægtPanel.add(weighttxt, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 10, 150, -1));

        TOPPanel.add(VægtPanel);
        VægtPanel.setBounds(410, 350, 400, 40);

        pricePanel.setOpaque(false);
        pricePanel.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        Label7.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        Label7.setForeground(new java.awt.Color(255, 255, 255));
        Label7.setText("Pris:");
        pricePanel.add(Label7, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 11, -1, -1));

        prisLabel.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        prisLabel.setForeground(new java.awt.Color(255, 255, 255));
        pricePanel.add(prisLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 10, 228, 29));

        TOPPanel.add(pricePanel);
        pricePanel.setBounds(400, 430, 410, 40);

        descriptionPanel.setOpaque(false);

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        jLabel9.setForeground(new java.awt.Color(255, 255, 255));
        jLabel9.setText("Bemærkninger:");

        descriptionArea.setColumns(20);
        descriptionArea.setRows(5);
        descriptionArea.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                descriptionAreaFocusLost(evt);
            }
        });
        jScrollPane2.setViewportView(descriptionArea);

        javax.swing.GroupLayout descriptionPanelLayout = new javax.swing.GroupLayout(descriptionPanel);
        descriptionPanel.setLayout(descriptionPanelLayout);
        descriptionPanelLayout.setHorizontalGroup(
            descriptionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(descriptionPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(descriptionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE)
                    .addGroup(descriptionPanelLayout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        descriptionPanelLayout.setVerticalGroup(
            descriptionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(descriptionPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel9)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(14, Short.MAX_VALUE))
        );

        TOPPanel.add(descriptionPanel);
        descriptionPanel.setBounds(0, 470, 400, 170);

        driverVehiclePanel.setOpaque(false);

        driverCombo.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                driverComboItemStateChanged(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        jLabel3.setForeground(new java.awt.Color(255, 255, 255));
        jLabel3.setText("Chauffør:");

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        jLabel5.setForeground(new java.awt.Color(255, 255, 255));
        jLabel5.setText("Køretøj:");

        vehicleCombo.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                vehicleComboItemStateChanged(evt);
            }
        });

        javax.swing.GroupLayout driverVehiclePanelLayout = new javax.swing.GroupLayout(driverVehiclePanel);
        driverVehiclePanel.setLayout(driverVehiclePanelLayout);
        driverVehiclePanelLayout.setHorizontalGroup(
            driverVehiclePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, driverVehiclePanelLayout.createSequentialGroup()
                .addGroup(driverVehiclePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(driverVehiclePanelLayout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel3)
                        .addGap(18, 18, 18))
                    .addGroup(driverVehiclePanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addGroup(driverVehiclePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(vehicleCombo, 0, 282, Short.MAX_VALUE)
                    .addComponent(driverCombo, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(28, 28, 28))
        );
        driverVehiclePanelLayout.setVerticalGroup(
            driverVehiclePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, driverVehiclePanelLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(driverVehiclePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(driverCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(driverVehiclePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(vehicleCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(73, 73, 73))
        );

        TOPPanel.add(driverVehiclePanel);
        driverVehiclePanel.setBounds(410, 500, 390, 110);

        Label6.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        Label6.setForeground(new java.awt.Color(255, 255, 255));
        Label6.setText("Farligt gods:");
        TOPPanel.add(Label6);
        Label6.setBounds(410, 400, 90, 16);

        antalKmLabel.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        antalKmLabel.setForeground(new java.awt.Color(255, 255, 255));
        TOPPanel.add(antalKmLabel);
        antalKmLabel.setBounds(450, 320, 260, 20);

        add(TOPPanel, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 60, 810, 650));

        clearKnap.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pictures/Ryd knap.png"))); // NOI18N
        clearKnap.setContentAreaFilled(false);
        clearKnap.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clearKnapActionPerformed(evt);
            }
        });
        add(clearKnap, new org.netbeans.lib.awtextra.AbsoluteConstraints(700, 10, 130, 50));

        background.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pictures/Baggrund 2.PNG"))); // NOI18N
        add(background, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 830, 720));
    }// </editor-fold>//GEN-END:initComponents

    private void tilbageKnapActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tilbageKnapActionPerformed
        main.visStartPanel();
    }//GEN-LAST:event_tilbageKnapActionPerformed

    private void opretOpgaveKnapActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_opretOpgaveKnapActionPerformed
        taskHandler = main.getTaskHandler();
        int beforeInsertSize = taskHandler.getTaskList().size();
        taskHandler.insertToDB(theTask);

        if (beforeInsertSize < taskHandler.getTaskList().size()) {
            JOptionPane.showMessageDialog(this, "Opgaven er oprettet!");
            clearFields();
        } else {
            JOptionPane.showMessageDialog(this, "Opgaven er IKKE oprettet!");
        }
        setCargo();
        setVehicleCombo();
        setDriverCombo();
        setFields();
    }//GEN-LAST:event_opretOpgaveKnapActionPerformed

    private void PallefragtRadioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PallefragtRadioActionPerformed
        cargoType = "pallet";
        fragtEnhedLabel.setText("Paller");
        setDriverCombo();
        setVehicleCombo();
        setCargo();
        setFields();
    }//GEN-LAST:event_PallefragtRadioActionPerformed

    private void afhentCompanytxtFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_afhentCompanytxtFocusGained
        afhentCompanytxt.selectAll();
    }//GEN-LAST:event_afhentCompanytxtFocusGained

    private void tlfnrTxtFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tlfnrTxtFocusGained
        tlfnrTxt.selectAll();
    }//GEN-LAST:event_tlfnrTxtFocusGained
    private void kundenavntxtFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_kundenavntxtFocusGained
        kundenavntxt.selectAll();
    }//GEN-LAST:event_kundenavntxtFocusGained
    private void kundeAdrTxtFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_kundeAdrTxtFocusGained
        kundeAdrTxt.selectAll();
    }//GEN-LAST:event_kundeAdrTxtFocusGained
    private void kundePostnrTxtFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_kundePostnrTxtFocusGained
        kundePostnrTxt.selectAll();
    }//GEN-LAST:event_kundePostnrTxtFocusGained
    private void kundeByTxtFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_kundeByTxtFocusGained
        kundeByTxt.selectAll();
    }//GEN-LAST:event_kundeByTxtFocusGained

    private void afhentAdrFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_afhentAdrFocusGained
        afhentAdr.selectAll();
    }//GEN-LAST:event_afhentAdrFocusGained
    private void afhentdisFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_afhentdisFocusGained
        if (afhentdis.getText().contains("Distrikt")) {
            afhentdis.setText("(Kan efterlades blank)");
        }
        afhentdis.selectAll();
    }//GEN-LAST:event_afhentdisFocusGained

    private void levcomFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_levcomFocusGained
        levcom.selectAll();
    }//GEN-LAST:event_levcomFocusGained
    private void levadrtxtFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_levadrtxtFocusGained
        levadrtxt.selectAll();
    }//GEN-LAST:event_levadrtxtFocusGained
    private void levzipFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_levzipFocusGained
        levzip.selectAll();
    }//GEN-LAST:event_levzipFocusGained
    private void levdisFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_levdisFocusGained
        if (levdis.getText().contains("Distrikt")) {
            levdis.setText("(Kan efterlades blank)");
        }
        levdis.selectAll();
    }//GEN-LAST:event_levdisFocusGained
    private void levLandFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_levLandFocusGained
        levLand.selectAll();
    }//GEN-LAST:event_levLandFocusGained

    private void AntalfragtFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_AntalfragtFocusGained
        Antalfragt.selectAll();
    }//GEN-LAST:event_AntalfragtFocusGained

    private void afhentCompanytxtFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_afhentCompanytxtFocusLost
        if (afhentCompanytxt.getText().equals("Firmanavn (Kan efterlades blank)")) {
            afhentCompanytxt.setText("");
        }
        if (!afhentCompanytxt.getText().equals("")) {
            Address curAddress = addressHandler.getAddressByCompany(afhentCompanytxt.getText());
            if (curAddress != null) {
                afhentCompanytxt.setText(curAddress.getCompany());
                afhentAdr.setText(curAddress.getAddress());
                afhentzip.setText(curAddress.getZipcode() + "");
                afhentByCombo.setSelectedItem(curAddress.getCity());
                afhentdis.setText(curAddress.getDistrict());
                afhentLand.setText(curAddress.getCountry());
            }
        }
        checkPickUpAddress();
    }//GEN-LAST:event_afhentCompanytxtFocusLost
    private void afhentAdrFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_afhentAdrFocusLost
        checkPickUpAddress();
    }//GEN-LAST:event_afhentAdrFocusLost
    private void afhentdisFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_afhentdisFocusLost
        if (afhentdis.getText().equals("(Kan efterlades blank)")) {
            afhentdis.setText("");
        }
        checkPickUpAddress();
    }//GEN-LAST:event_afhentdisFocusLost

    private void levcomFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_levcomFocusLost
        if (levcom.getText().equals("Firmanavn (Kan efterlades blank)")) {
            levcom.setText("");
        }
        if (!levcom.getText().equals("")) {
            Address curAddress = addressHandler.getAddressByCompany(levcom.getText());
            if (curAddress != null) {
                levcom.setText(curAddress.getCompany());
                levadrtxt.setText(curAddress.getAddress());
                levzip.setText(curAddress.getZipcode() + "");
                levByCombo.setSelectedItem(curAddress.getCity());
                levdis.setText(curAddress.getDistrict());
                levLand.setText(curAddress.getCountry());
            }
        }
        checkDeliveryAddress();
    }//GEN-LAST:event_levcomFocusLost
    private void levadrtxtFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_levadrtxtFocusLost
        checkDeliveryAddress();
    }//GEN-LAST:event_levadrtxtFocusLost
    private void levzipFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_levzipFocusLost
        checkDeliveryAddress();
    }//GEN-LAST:event_levzipFocusLost
    private void levdisFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_levdisFocusLost
        if (levdis.getText().equals("(Kan efterlades blank)")) {
            levdis.setText("");
        }
        checkDeliveryAddress();
    }//GEN-LAST:event_levdisFocusLost
    private void levLandFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_levLandFocusLost
        checkDeliveryAddress();
    }//GEN-LAST:event_levLandFocusLost

    private void tlfnrTxtFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tlfnrTxtFocusLost
//        Customer aCustomer = null;
//        if (tlfnrTxt.getText().matches("\\d+")) {
//            aCustomer = customerHandler.getCustomerByPhoneNo(Integer.parseInt(tlfnrTxt.getText()));
//            if (aCustomer != null) {
//                kundenavntxt.setText(aCustomer.getCompanyName());
//                kundeAdrTxt.setText(aCustomer.getAddress());
//                kundePostnrTxt.setText(aCustomer.getZipcode() + "");
//                kundeByTxt.setText(aCustomer.getCity());
//                customer = aCustomer;
//                setCustomer();
//            }
//        }
//        setFields();
    }//GEN-LAST:event_tlfnrTxtFocusLost

    private void StykGodsRadioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_StykGodsRadioActionPerformed
        cargoType = "cargo";
        fragtEnhedLabel.setText("m³");
        setCargo();
        setVehicleCombo();
        setDriverCombo();
        setFields();
    }//GEN-LAST:event_StykGodsRadioActionPerformed
    private void SpecielFragtRadioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SpecielFragtRadioActionPerformed
        cargoType = "special";
        fragtEnhedLabel.setText("m³");
        setCargo();
        setVehicleCombo();
        setDriverCombo();
        setFields();
    }//GEN-LAST:event_SpecielFragtRadioActionPerformed
    private void AntalfragtFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_AntalfragtFocusLost
//        if(Antalfragt.getText().matches("\\d+")){
//            cargoNumber = Integer.parseInt(Antalfragt.getText());
//        }
//        setCargo();
//        setVehicleCombo();
//        setFields();
    }//GEN-LAST:event_AntalfragtFocusLost
    private void farligtGodsCheckActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_farligtGodsCheckActionPerformed
        dangCargo = farligtGodsCheck.isSelected();
        setCargo();
        setDriverCombo();
        setVehicleCombo();
        setFields();
    }//GEN-LAST:event_farligtGodsCheckActionPerformed

    private void driverComboItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_driverComboItemStateChanged
        theTask.setDriver((Driver) driverCombo.getSelectedItem());
//        setFields();
    }//GEN-LAST:event_driverComboItemStateChanged

    private void vehicleComboItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_vehicleComboItemStateChanged
        theTask.setVehicle((Vehicle) vehicleCombo.getSelectedItem());
//        setFields();
    }//GEN-LAST:event_vehicleComboItemStateChanged

    private void weighttxtFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_weighttxtFocusLost
//        if (weighttxt.getText().matches("\\d+")) {
//            cargoWeight = Integer.parseInt(weighttxt.getText());
//        }
//        setCargo();
//        setVehicleCombo();
//        setDriverCombo();
//        setFields();
    }//GEN-LAST:event_weighttxtFocusLost

    private void descriptionAreaFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_descriptionAreaFocusLost
        if (descriptionArea.getText() != null) {
            description = descriptionArea.getText();
            theTask.setDescription(description);
        } else {
            System.out.println("Description er null YAY! 8D");
        }
        setFields();
    }//GEN-LAST:event_descriptionAreaFocusLost

    private void weighttxtFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_weighttxtFocusGained
        weighttxt.selectAll();
    }//GEN-LAST:event_weighttxtFocusGained

    private void sameAsCustomer_KnapActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sameAsCustomer_KnapActionPerformed
        afhentCompanytxt.setText(kundenavntxt.getText());
        afhentAdr.setText(kundeAdrTxt.getText());
        afhentzip.setText(kundePostnrTxt.getText());
        afhentByCombo.setSelectedItem(kundeByTxt.getText());
        if (customer != null) {
            afhentdis.setText(customer.getDistrict());
            afhentLand.setText(customer.getCountry());
        } else {
            System.out.println("OMG costumer er null");
        }
        if (!afhentCompanytxt.getText().equals("")) {
            Address curAddress = addressHandler.getAddressByCompany(afhentCompanytxt.getText());
            if (curAddress != null) {
                afhentAdr.setText(curAddress.getAddress());
                afhentzip.setText(curAddress.getZipcode() + "");
                afhentByCombo.setSelectedItem(curAddress.getCity());
                afhentdis.setText(curAddress.getDistrict());
                afhentLand.setText(curAddress.getCountry());
            }
            pickUpAddress = curAddress;
        }
        checkPickUpAddress();
    }//GEN-LAST:event_sameAsCustomer_KnapActionPerformed

    private void formComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentShown
        main.setSize(845, 780);

        if (tlfnrTxt.getText().equals("0")) {
            tlfnrTxt.setText("");
        }
        afhentByCombo.removeAllItems();
        levByCombo.removeAllItems();

        for (int i = 0; i < distanceHandler.getAllCities().size(); i++) {
            afhentByCombo.addItem(distanceHandler.getAllCities().get(i));
            levByCombo.addItem(distanceHandler.getAllCities().get(i));
        }
    }//GEN-LAST:event_formComponentShown
    private void sameAsCustomerDelKnapActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sameAsCustomerDelKnapActionPerformed
        levcom.setText(kundenavntxt.getText());
        levadrtxt.setText(kundeAdrTxt.getText());
        levzip.setText(kundePostnrTxt.getText());
        levByCombo.setSelectedItem(kundeByTxt.getText());
        if (customer != null) {
            levdis.setText(customer.getDistrict());
            levLand.setText(customer.getCountry());
        }

        if (!levcom.getText().equals("")) {
            if (addressHandler.tjekAddressByCompany(levcom.getText())) {
                Address curAddress = addressHandler.getAddressByCompany(levcom.getText());
                if (curAddress != null) {
                    levadrtxt.setText(curAddress.getAddress());
                    levzip.setText(curAddress.getZipcode() + "");
                    levByCombo.setSelectedItem(curAddress.getCity());
                    levdis.setText(curAddress.getDistrict());
                    levLand.setText(curAddress.getCountry());
                }
                deliveryAddress = curAddress;
                theTask.setDeliveryAddress(deliveryAddress);
            }
        }
        checkDeliveryAddress();
    }//GEN-LAST:event_sameAsCustomerDelKnapActionPerformed

    private void OpretNyKundeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OpretNyKundeActionPerformed
        if (tlfnrTxt.getText().matches("\\d+")) {
//            System.out.println("TLF: "+tlfnrTxt.getText());
            main.setCurCustomerPhone(Integer.parseInt(tlfnrTxt.getText()));
        } else {
            main.setCurCustomerPhone(0);
        }
        main.visOpretKundeDialog();
    }//GEN-LAST:event_OpretNyKundeActionPerformed

    private void jCalendar1PropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_jCalendar1PropertyChange
        setVehicleCombo();
        setDriverCombo();
        setFields();
    }//GEN-LAST:event_jCalendar1PropertyChange

    private void tlfnrTxtKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tlfnrTxtKeyReleased
        Customer aCustomer = null;
        if (tlfnrTxt.getText().matches("\\d+") && tlfnrTxt.getText().length() <= 10) {
            aCustomer = customerHandler.getCustomerByPhoneNo(Integer.parseInt(tlfnrTxt.getText()));
            if (aCustomer != null) {
                kundenavntxt.setText(aCustomer.getCompanyName());
                kundeAdrTxt.setText(aCustomer.getAddress());
                kundePostnrTxt.setText(aCustomer.getZipcode() + "");
                kundeByTxt.setText(aCustomer.getCity());
                customer = aCustomer;
                theTask.setCustomer(customer);
                setCustomer();
//                System.out.println("HEJ MED DIG! :D");
            } else {
                kundenavntxt.setText("");
                kundeAdrTxt.setText("");
                kundePostnrTxt.setText("");
                kundeByTxt.setText("");
                customer = null;
                theTask.setCustomer(customer);
                setCustomer();
            }
        }
        setFields();
    }//GEN-LAST:event_tlfnrTxtKeyReleased

    private void weighttxtKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_weighttxtKeyReleased
        if (weighttxt.getText().matches("\\d+")) {
            cargoWeight = Integer.parseInt(weighttxt.getText());
        }
        setCargo();
        setVehicleCombo();
        setDriverCombo();
        setFields();
    }//GEN-LAST:event_weighttxtKeyReleased

    private void AntalfragtKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_AntalfragtKeyReleased
        if (Antalfragt.getText().matches("\\d+")) {
            cargoNumber = Integer.parseInt(Antalfragt.getText());
        }
        setCargo();
        setVehicleCombo();
        setFields();
    }//GEN-LAST:event_AntalfragtKeyReleased

    private void clearKnapActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearKnapActionPerformed
        clearFields();
    }//GEN-LAST:event_clearKnapActionPerformed

    private void afhentLandFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_afhentLandFocusLost
        checkPickUpAddress();
    }//GEN-LAST:event_afhentLandFocusLost

    private void afhentLandFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_afhentLandFocusGained
        afhentLand.selectAll();
    }//GEN-LAST:event_afhentLandFocusGained

    private void afhentzipFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_afhentzipFocusLost
        checkPickUpAddress();
    }//GEN-LAST:event_afhentzipFocusLost

    private void afhentzipFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_afhentzipFocusGained
        afhentzip.selectAll();
    }//GEN-LAST:event_afhentzipFocusGained

    private void afhentByComboItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_afhentByComboItemStateChanged
        if (!clearRunning) {
            afhentzip.setText(distanceHandler.getZipcodeByCity((String) afhentByCombo.getSelectedItem()));
            afhentLand.setText(distanceHandler.getCountryByCity((String) afhentByCombo.getSelectedItem()));
            checkPickUpAddress();
        }
    }//GEN-LAST:event_afhentByComboItemStateChanged

    private void levByComboItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_levByComboItemStateChanged
        if (!clearRunning) {
            levzip.setText(distanceHandler.getZipcodeByCity((String) levByCombo.getSelectedItem()));
            levLand.setText(distanceHandler.getCountryByCity((String) levByCombo.getSelectedItem()));
            checkDeliveryAddress();
        }
    }//GEN-LAST:event_levByComboItemStateChanged
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel AfhentningsAdressePanel;
    private javax.swing.JTextField Antalfragt;
    private javax.swing.JPanel KmPanel;
    private javax.swing.JLabel Label6;
    private javax.swing.JLabel Label7;
    private javax.swing.JLabel Label8;
    private javax.swing.JLabel Label9;
    private javax.swing.JButton OpretNyKunde;
    private javax.swing.JRadioButton PallefragtRadio;
    private javax.swing.JLabel RuteLabel;
    private javax.swing.JRadioButton SpecielFragtRadio;
    private javax.swing.JLabel StatusLabel;
    private javax.swing.JRadioButton StykGodsRadio;
    private javax.swing.JPanel TOPPanel;
    private javax.swing.JLabel TitelLabel;
    private javax.swing.JPanel VægtPanel;
    private javax.swing.JTextField afhentAdr;
    private javax.swing.JComboBox afhentByCombo;
    private javax.swing.JTextField afhentCompanytxt;
    private javax.swing.JTextField afhentLand;
    private javax.swing.JTextField afhentdis;
    private javax.swing.JLabel afhentningsadresseLabel;
    private javax.swing.JTextField afhentzip;
    private javax.swing.JLabel antalKmLabel;
    private javax.swing.JLabel background;
    private javax.swing.ButtonGroup cargoButtonGroup;
    private javax.swing.JButton clearKnap;
    private javax.swing.JTextArea descriptionArea;
    private javax.swing.JPanel descriptionPanel;
    private javax.swing.JComboBox driverCombo;
    private javax.swing.JPanel driverVehiclePanel;
    private javax.swing.JCheckBox farligtGodsCheck;
    private javax.swing.JLabel fragtEnhedLabel;
    private com.toedter.calendar.JCalendar jCalendar1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JSeparator jSeparator5;
    private javax.swing.JSeparator jSeparator6;
    private javax.swing.JSeparator jSeparator7;
    private javax.swing.JTextField kundeAdrTxt;
    private javax.swing.JTextField kundeByTxt;
    private javax.swing.JTextField kundePostnrTxt;
    private javax.swing.JTextField kundenavntxt;
    private javax.swing.JComboBox levByCombo;
    private javax.swing.JTextField levLand;
    private javax.swing.JTextField levadrtxt;
    private javax.swing.JTextField levcom;
    private javax.swing.JTextField levdis;
    private javax.swing.JTextField levzip;
    private javax.swing.JButton opretOpgaveKnap;
    private javax.swing.JPanel pricePanel;
    private javax.swing.JLabel prisLabel;
    private javax.swing.JButton sameAsCustomerDelKnap;
    private javax.swing.JButton sameAsCustomer_Knap;
    private javax.swing.JButton tilbageKnap;
    private javax.swing.JTextField tlfnrTxt;
    private javax.swing.JComboBox vehicleCombo;
    private javax.swing.JTextField weighttxt;
    // End of variables declaration//GEN-END:variables
}
